package com.amtf.datafile3.core.excel;

import java.io.File;

import com.amtf.datafile3.DataCatalog;
import com.amtf.datafile3.DataException;
import com.amtf.datafile3.DataFile;
import com.amtf.datafile3.DataTableDefinition;

public class ExcelDataFile extends DataFile {
	private static final long serialVersionUID = -756675084921496671L;
	private int startRow;
	private int startColumn;
	private boolean firstRowTitle;

	public ExcelDataFile(File file, int startRow, boolean firstRowTitle) {
		this(null, file, startRow, 0, firstRowTitle);
	}

	public ExcelDataFile(File file, int startRow, int startColumn, boolean firstRowTitle) {
		this(null, file, startRow, startColumn, firstRowTitle);
	}

	public ExcelDataFile(DataTableDefinition definition, File file, int startRow, int startColumn, boolean firstRowTitle) {
		super(definition, file);
		this.startRow = startRow;
		this.startColumn = startColumn;
		this.firstRowTitle = firstRowTitle;
		dataAccessor = new ExcelDataAccessor();
	}

	public DataCatalog openCatalog() throws DataException {
		DataCatalog dc = dataAccessor.open("file:///" + this.getPath() + "?startReadRow=" + startRow + "&startReadColumn=" + startColumn + "&firstRowTitle=" + firstRowTitle);
		if (definition != null) {
			dc.setDataTableDefinition(definition);
		}
		return dc;
	}
}
